package com.flymobi.admin;

import java.util.List;

import com.flymobi.fw.modules.SM;
import com.flymobi.fw.util.StringUtil;
import com.flymobi.po.Block;
import com.flymobi.po.Manager;
import com.flymobi.po.PageBlock;
import com.flymobi.po.PageContent;
import com.flymobi.util.C;
import com.flymobi.util.WebContext;

/**
 * 
 * 
 * Title:
 * 
 * Description:
 * 
 * Copyright: Copyright (c) 2008
 * 
 * @author haoxz11
 * @created Oct 21, 2008 11:16:42 AM
 * @version $Id: ManagerAction.java,v 1.1 2010/04/09 03:27:08 airsou Exp $
 */
public class PageContentAction extends WebAction {
	private String pageid;

	private Block block;
	
	private PageContent pageContent;

	/**
	 * @return the pageContent
	 */
	public PageContent getPageContent() {
		return pageContent;
	}

	/**
	 * @param pageContent the pageContent to set
	 */
	public void setPageContent(PageContent pageContent) {
		this.pageContent = pageContent;
	}

	/**
	 * @return the pageid
	 */
	public String getPageid() {
		return pageid;
	}

	/**
	 * @param pageid the pageid to set
	 */
	public void setPageid(String pageid) {
		this.pageid = pageid;
	}

	/**
	 * @return the block
	 */
	public Block getBlock() {
		return block;
	}

	/**
	 * @param block
	 *            the block to set
	 */
	public void setBlock(Block block) {
		this.block = block;
	}


	/**
	 * Comment for <code>serialVersionUID</code>
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public String webProcess(WebContext context, Manager manager) {
		if(StringUtil.isEmpty(pageid)){
			pageid="0";
		}
		if ("editpage".equals(method)) {
			List<PageContent> pagecontentList = SM.PageContentService.list(new Long(pageid), 0, 1000);
			context.put("pagecontentList", pagecontentList);
			return "editpage";
		}
		
		
		else if ("addblock".equals(method)) {
			return "editblock";
		}else if ("editblock".equals(method)) {
			PageContent pageContent=SM.PageContentService.get(id);
			context.put("pageContent", pageContent);
			context.put("block", pageContent.getBlock());
			return "editblock";
		}else if ("saveblock".equals(method)) {
			block.setType(2L);
			block.setBlockType(1L);
			SM.BlockService.save(block);
			pageContent.setPage(new Long(pageid));
			pageContent.setContId(block.getId());
			pageContent.setType("1");
			if(this.isEmptyId(pageContent)){
				SM.PageContentService.save(pageContent);
				pageContent.setIdx(pageContent.getId());
			}
			SM.PageContentService.save(pageContent);
			context.put("rmsg", C.TEXT.SAVE_SUCCESS);
			return "saveblock";
		}
		
		else if ("addnewsblock".equals(method)) {
			List<PageBlock> pageBlockList=SM.PageBlockService.list(0, 100);
			context.put("pageBlockList", pageBlockList);
			return "editnewsblock";
		}else if ("editnewsblock".equals(method)) {
			Block block=SM.BlockService.get(id);
			context.put("block", block);
			return "editnewsblock";
		}else if ("savenewsblock".equals(method)) {
			pageContent.setPage(new Long(pageid));
			pageContent.setType("2");
			if(this.isEmptyId(pageContent)){
				SM.PageContentService.save(pageContent);
				pageContent.setIdx(pageContent.getId());
			}
			SM.PageContentService.save(pageContent);
			method="editpage";
			return this.webProcess(context, manager);
		}
		
		
		else if ("deleteblock".equals(method)) {
			SM.PageContentService.delete(id);
			id=pageid;
			context.put("rmsg", C.TEXT.DELETE_SUCCESS);
			method = "editpage";
			return this.webProcess(context, manager);
		}else if ("up".equals(method)) {
			SM.PageContentService.updateUp(id);
			context.put("rmsg", C.TEXT.OPERA_SUCCESS);
			id=pageid;
			method = "editpage";
			return this.webProcess(context, manager);
		}else if ("down".equals(method)) {
			SM.PageContentService.updateDown(id);
			context.put("rmsg", C.TEXT.OPERA_SUCCESS);
			id=pageid;
			method = "editpage";
			return this.webProcess(context, manager);
		}  else {
			method = "editpage";
			return this.webProcess(context, manager);
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.camel.admin.WebAction#getSysLog()
	 */
	@Override
	public String getSysLog() {
		String opr = "";

		return opr;
	}
}
